﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CarFrameWork.Common;
namespace CarFrameWork.Model
{
	/// <summary>
	/// 类主动齿轮。
	/// </summary>
	[Serializable]
	public partial class 主动齿轮
	{
		public 主动齿轮()
		{}
		#region Model
		private string _id;
		private string _name;
		private float _l2;
		private float _l4;
		private float _l10;
		private float _l16;
		private float _l18;
		private float _d2;
		private float _d4;
		private float _d8;
		private float _d9;
		private float _d10;
		/// <summary>
		/// 
		/// </summary>
		public string ID
		{
			set{ _id=value;}
			get{return _id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string name
		{
			set{ _name=value;}
			get{return _name;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float L2
		{
			set{ _l2=value;}
			get{return _l2;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float L4
		{
			set{ _l4=value;}
			get{return _l4;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float L10
		{
			set{ _l10=value;}
			get{return _l10;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float L16
		{
			set{ _l16=value;}
			get{return _l16;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float L18
		{
			set{ _l18=value;}
			get{return _l18;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D2
		{
			set{ _d2=value;}
			get{return _d2;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D4
		{
			set{ _d4=value;}
			get{return _d4;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D8
		{
			set{ _d8=value;}
			get{return _d8;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D9
		{
			set{ _d9=value;}
			get{return _d9;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D10
		{
			set{ _d10=value;}
			get{return _d10;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public 主动齿轮(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,L2,L4,L10,L16,L18,D2,D4,D8,D9,D10 ");
			strSql.Append(" FROM [主动齿轮] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.NVarChar)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["L2"]!=null && ds.Tables[0].Rows[0]["L2"].ToString()!="")
				{
					this.L2=float.Parse(ds.Tables[0].Rows[0]["L2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L4"]!=null && ds.Tables[0].Rows[0]["L4"].ToString()!="")
				{
					this.L4=float.Parse(ds.Tables[0].Rows[0]["L4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L10"]!=null && ds.Tables[0].Rows[0]["L10"].ToString()!="")
				{
					this.L10=float.Parse(ds.Tables[0].Rows[0]["L10"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L16"]!=null && ds.Tables[0].Rows[0]["L16"].ToString()!="")
				{
					this.L16=float.Parse(ds.Tables[0].Rows[0]["L16"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L18"]!=null && ds.Tables[0].Rows[0]["L18"].ToString()!="")
				{
					this.L18=float.Parse(ds.Tables[0].Rows[0]["L18"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D2"]!=null && ds.Tables[0].Rows[0]["D2"].ToString()!="")
				{
					this.D2=float.Parse(ds.Tables[0].Rows[0]["D2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D4"]!=null && ds.Tables[0].Rows[0]["D4"].ToString()!="")
				{
					this.D4=float.Parse(ds.Tables[0].Rows[0]["D4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D8"]!=null && ds.Tables[0].Rows[0]["D8"].ToString()!="")
				{
					this.D8=float.Parse(ds.Tables[0].Rows[0]["D8"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D9"]!=null && ds.Tables[0].Rows[0]["D9"].ToString()!="")
				{
					this.D9=float.Parse(ds.Tables[0].Rows[0]["D9"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D10"]!=null && ds.Tables[0].Rows[0]["D10"].ToString()!="")
				{
					this.D10=float.Parse(ds.Tables[0].Rows[0]["D10"].ToString());
				}
			}
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [主动齿轮]");
			strSql.Append(" where ID=@ID ");

			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.NVarChar)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [主动齿轮] (");
			strSql.Append("ID,name,L2,L4,L10,L16,L18,D2,D4,D8,D9,D10)");
			strSql.Append(" values (");
			strSql.Append("@ID,@name,@L2,@L4,@L10,@L16,@L18,@D2,@D4,@D8,@D9,@D10)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.NVarChar,50),
					new SqlParameter("@name", SqlDbType.Text),
					new SqlParameter("@L2", SqlDbType.Float,8),
					new SqlParameter("@L4", SqlDbType.Float,8),
					new SqlParameter("@L10", SqlDbType.Float,8),
					new SqlParameter("@L16", SqlDbType.Float,8),
					new SqlParameter("@L18", SqlDbType.Float,8),
					new SqlParameter("@D2", SqlDbType.Float,8),
					new SqlParameter("@D4", SqlDbType.Float,8),
					new SqlParameter("@D8", SqlDbType.Float,8),
					new SqlParameter("@D9", SqlDbType.Float,8),
					new SqlParameter("@D10", SqlDbType.Float,8)};
			parameters[0].Value = ID;
			parameters[1].Value = name;
			parameters[2].Value = L2;
			parameters[3].Value = L4;
			parameters[4].Value = L10;
			parameters[5].Value = L16;
			parameters[6].Value = L18;
			parameters[7].Value = D2;
			parameters[8].Value = D4;
			parameters[9].Value = D8;
			parameters[10].Value = D9;
			parameters[11].Value = D10;

			DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [主动齿轮] set ");
			strSql.Append("name=@name,");
			strSql.Append("L2=@L2,");
			strSql.Append("L4=@L4,");
			strSql.Append("L10=@L10,");
			strSql.Append("L16=@L16,");
			strSql.Append("L18=@L18,");
			strSql.Append("D2=@D2,");
			strSql.Append("D4=@D4,");
			strSql.Append("D8=@D8,");
			strSql.Append("D9=@D9,");
			strSql.Append("D10=@D10");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.Text),
					new SqlParameter("@L2", SqlDbType.Float,8),
					new SqlParameter("@L4", SqlDbType.Float,8),
					new SqlParameter("@L10", SqlDbType.Float,8),
					new SqlParameter("@L16", SqlDbType.Float,8),
					new SqlParameter("@L18", SqlDbType.Float,8),
					new SqlParameter("@D2", SqlDbType.Float,8),
					new SqlParameter("@D4", SqlDbType.Float,8),
					new SqlParameter("@D8", SqlDbType.Float,8),
					new SqlParameter("@D9", SqlDbType.Float,8),
					new SqlParameter("@D10", SqlDbType.Float,8),
					new SqlParameter("@ID", SqlDbType.NVarChar,50)};
			parameters[0].Value = name;
			parameters[1].Value = L2;
			parameters[2].Value = L4;
			parameters[3].Value = L10;
			parameters[4].Value = L16;
			parameters[5].Value = L18;
			parameters[6].Value = D2;
			parameters[7].Value = D4;
			parameters[8].Value = D8;
			parameters[9].Value = D9;
			parameters[10].Value = D10;
			parameters[11].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [主动齿轮] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.NVarChar)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,L2,L4,L10,L16,L18,D2,D4,D8,D9,D10 ");
			strSql.Append(" FROM [主动齿轮] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.NVarChar)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["L2"]!=null && ds.Tables[0].Rows[0]["L2"].ToString()!="")
				{
					this.L2=float.Parse(ds.Tables[0].Rows[0]["L2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L4"]!=null && ds.Tables[0].Rows[0]["L4"].ToString()!="")
				{
					this.L4=float.Parse(ds.Tables[0].Rows[0]["L4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L10"]!=null && ds.Tables[0].Rows[0]["L10"].ToString()!="")
				{
					this.L10=float.Parse(ds.Tables[0].Rows[0]["L10"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L16"]!=null && ds.Tables[0].Rows[0]["L16"].ToString()!="")
				{
					this.L16=float.Parse(ds.Tables[0].Rows[0]["L16"].ToString());
				}
				if(ds.Tables[0].Rows[0]["L18"]!=null && ds.Tables[0].Rows[0]["L18"].ToString()!="")
				{
					this.L18=float.Parse(ds.Tables[0].Rows[0]["L18"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D2"]!=null && ds.Tables[0].Rows[0]["D2"].ToString()!="")
				{
					this.D2=float.Parse(ds.Tables[0].Rows[0]["D2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D4"]!=null && ds.Tables[0].Rows[0]["D4"].ToString()!="")
				{
					this.D4=float.Parse(ds.Tables[0].Rows[0]["D4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D8"]!=null && ds.Tables[0].Rows[0]["D8"].ToString()!="")
				{
					this.D8=float.Parse(ds.Tables[0].Rows[0]["D8"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D9"]!=null && ds.Tables[0].Rows[0]["D9"].ToString()!="")
				{
					this.D9=float.Parse(ds.Tables[0].Rows[0]["D9"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D10"]!=null && ds.Tables[0].Rows[0]["D10"].ToString()!="")
				{
					this.D10=float.Parse(ds.Tables[0].Rows[0]["D10"].ToString());
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [主动齿轮] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

